#!/bin/dash
{
	#////////////////////////////////////
	# DietPi Kodi run script
	#
	#////////////////////////////////////
	# Created by Daniel Knight / daniel.knight@dietpi.com / dietpi.com
	#
	#////////////////////////////////////
	#
	# Info:
	# - Location: /boot/dietpi/misc/start_kodi
	# - Starts Kodi the correct way for various HW models from desktop and console
	#
	# Usage:
	# - /boot/dietpi/misc/start_kodi
	#////////////////////////////////////

	# Load $G_HW_MODEL
	. /boot/dietpi/.hw_model

	#/////////////////////////////////////////////////////////////////////////////////////
	# Main Loop
	#/////////////////////////////////////////////////////////////////////////////////////
	# RPi + Odroid N2 + Odroid C4: Kodi is not built with X server support on those boards
	if [ "$G_HW_MODEL" -lt 10 ] || [ "$G_HW_MODEL" = 15 ] || [ "$G_HW_MODEL" = 16 ]; then

		exec kodi --standalone

	# Everything else
	# - From desktop
	elif [ "$DISPLAY" ]; then

		exec kodi

	# - From console
	else

		exec xinit "$(command -v kodi)" --standalone

	fi

	#-------------------------------------------------------------------------------------
	exit
	#-------------------------------------------------------------------------------------
}
